<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="../css/base.css" />
<link rel="stylesheet" href="../css/util.css" />
<link rel="stylesheet" href="../css/collect.css" />
<title>医美预约项目列表</title>
<style>
.head_area .public_input span{
	width: 100px;font-size: 18px;
}
.head_area .public_input input,
.head_area .public_input select{
	width: 280px;margin-left: 10px;
}
</style>
</head>
<body>
<div class="content user_list">
	<div class="navigate_head clearfix">
		<p onclick="window.location.href='appoint_proj_list.html'" class="navi_current">项目列表</p>
		<p onclick="window.location.href='add_appoint_proj.html'">添加项目</p>
		<p class="navi_null"></p>
	</div>
	<!--头部功能-->
	<div class="head_area flex_vertical" style="display: block;">
		<div class="public_input">
			<span >关键词：</span>
			<input type="text" class="keyword" placeholder="搜索患者（姓名、手机号）" style="width: 280px;"/>
		</div>
		<div class="public_input">
			<span>是否上架：</span>
			<select class="pass">
				<option value="">请选择</option>
				<option value="true">已上架</option>
				<option value="false">已下架</option>
			</select>
		</div>
		<button class="search">搜索</button>
		<div class="public_input">
			<span>项目类型：</span>
			<select class="proj_type">
				<option value="">请选择</option>
			</select>
		</div>
	</div>
	<table>
		<thead>
			<tr>
				<td>项目类型</td>
				<td>项目名称</td>
				<td>图片</td>
				<td>预约人数</td>
				<td>收藏数量</td>
				<td>用户评分</td>
				<td>是否上架</td>
				<td>操作</td>
			</tr>
		</thead>
		<tbody class="tbody">
			
		</tbody>
	</table>
	<!--分页-->
	<div class="page flex_vertical">
		<button class="" onclick="indexPage()">首页</button>&nbsp;
		<button class="" onclick="backPage()"><上一页</button>&nbsp;
		<!--页码-->
		<p class="page_num">
			<!--<span>1</span><span>2</span><span>3</span><span>4</span><span>5</span>-->
		</p>....
		<button class="" onclick="nextPage()">下一页></button>&nbsp;
		<button class="" onclick="endPage()">末页</button>&nbsp;
		共<span class="all_recode">0 </span>记录&nbsp;|
		共<span class="all_page">0 </span>页&nbsp;
		到第<input class="select_page" />页&nbsp;
		<button class="confirm_page" onclick="skipPage()">确定</button>
	</div>
</div>
<script type="text/javascript" src="../plug/jquery-1.11.3.js" ></script>
<script type="text/javascript" src="../plug/template-web.js"></script>
<script type="text/javascript" src="../js/toggle.js" ></script>
<script type="text/javascript" src="../js/util.js"></script>
<script type="text/javascript" src="../js/method.js"></script>
<script type="text/javascript" src="../js/page.js"></script>
<script id="test_appoint_list" type="text/html">
	{{each data value}}
		<tr>
			<td>{{value.subSubjectName}}</td>
			<td>{{value.name}}</td>
			<td width="150px" style="padding: 0;">
				{{if value.images}}
					{{each value.images tag}}
						<img src="{{tag}}" />
					{{/each}}
				{{/if}}
			</td>
			<td>{{value.orderQuantity}}</td>
			<td>{{value.favoriteQuantity}}</td>
			<td>{{value.score}}</td>
			<td>{{if value.marketable==true}}已上架{{else if value.marketable == false}}未上架{{/if}}</td>
			<td data_id = "{{value.id}}">
				<button class="font_green" onclick="edit_appoint_proj(this)">编辑</button>
				<!--&nbsp;<button class="font_green">删除</button>-->
			</td>
		</tr>
	{{/each}}
</script>
<!--项目类型列表-->
<script type="text/html" id="test_proj_list">
	{{each item value}}
		<option value="{{value.id}}">{{value.name}}</option>
	{{/each}}
</script>
<script>
//初始化项目类型列表
$.initSelect("/hospital/getSubjects.json","test_proj_list",".proj_type");
$.get_ajax("/hospital/getSubjects.json","",function(data){
	var html = template('test_proj_list',data.data[0]);
	$(".proj_type").append(html);
});

function edit_appoint_proj(m){
	var appoint_proj_id =  $(m).parent().attr("data_id");
	window.localStorage.setItem("appoint_proj_id",appoint_proj_id);
	window.location.href = "edit_appoint_proj.html";
}

//请求方法
function reqPage(data){
	console.log(data);
	control_page.init_page(data,function(data){
		//调用ajax
		$.get_ajax("/hospital/medical/beautyProject/getList.json",data,function(data){
			console.log(data);
			var html = template('test_appoint_list',data);
			$(".tbody").html(html);
			//初始化分页
			control_page.currentPage(control_page.page_num,data.totalCount);
		});
	});
}
</script>
<script>
var proj_type_id="";
var pass_val = "";
//项目类型
$(".proj_type").change(function(){
	proj_type_id = $(".proj_type").val();
	console.log(proj_type_id);
});
//是否上架
$(".pass").change(function(){
	pass_val = $(".pass").val();
	console.log(pass_val);
});
$(function(){
	reqPage(control_page.getData());
	//搜索
	$(".head_area .search").click(function(){
		//基本条件
//		var data = control_page.getData();
		var data = {
			"pageNumber":1,//当前页
			"pageSize":10//每页的长度
		}
		//关键词
		var keyword = $(".keyword").val();
		if(keyword != ""){
			data.keyword = keyword;
			console.log(data);
		}
//		console.log(pass_val);
		//是否上架
		if(pass_val != ""){
			data.marketable = pass_val;
			console.log(data);
		}
		//项目类型id
		console.log($.regNum(proj_type_id));
		if($.regNum(proj_type_id)){
			data.subjectId = proj_type_id;
			console.log(data);
		}
		console.log(data);
		reqPage(data);
	});
});
</script>
</body>
</html>
